<?php
	require_once("model/SQLiteRepository.php");
	require_once("model/ProducerDAL.php");

	$title = "Testar modellen";
	$body = "";

	$body .= "Skapar upp testdatabas, repository och DAL-klass...";
	$db = new PDO("sqlite:model/test.sqlite");
	$db->query("CREATE TABLE IF NOT EXISTS 'Producers' (latitude REAL, longitude REAL, producerID INTEGER PRIMARY KEY, description TEXT)");
	$testRepo = new SQLiteRepository($db);
	$dal = new ProducerDAL($testRepo);
	$body .= "...klar!<br/>";
	

	$body .= "Testar att skapa en producent...";
	$new = new Producer();
	$new->latitude = 66.6666;
	$new->longitude = 66.6666;
	$new->description = "hell's kitchen";
	
	$new = $dal->saveProducer($new);
	$body .= "...klar!<br/>";


	$body .= "Testar att hämta och redigera en producent...";
	$old = $dal->GetProducerById($new->producerID);
	$old->description = "Nisse Hult";
	$old = $dal->SaveProducer($old);
	$body .= "...klar!<br/>";

	$body .= "Testar att hämta och radera en producent...";
	$old = $dal->GetProducerById($new->producerID);
	$old = $dal->DeleteProducer($old);
	$body .= "...klar!<br/>";

	$body .= "Stänger uppkoppling och tar bort databas...";
	$db = null;
	unlink("model/test.sqlite");
	$body .= "...klar!<br/>";
			
	//Bygger upp xhtml-sidan och skriver ut den.
	$html = "
	<!DOCTYPE html>
	<html xmlns=\"http://www.w3.org/1999/xhtml\">
		<head> 
			<title>$title</title>
			<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />
		</head> 
		
		<body>
			$body
		</body>
	</html>";

	echo ($html);

?>